package com.zjgk.hotel.handler;




import com.zjgk.hotel.vo.Result;
import org.springframework.validation.BindException;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.validation.ConstraintViolationException;

@RestControllerAdvice
public class AllExceptionHandler {

    // 声明此方法处理ConstraintViolationException所产生的异常
    @ExceptionHandler(BindException.class)
    public Result doException(BindException e){
//        BindingResult bindingResult = e.getBindingResult();
        return new Result(Result.TRANSMIT_ERROR, "接收失败或接收参数空");
    }

    //

    @ExceptionHandler(RuntimeException.class)
    public Result doException(RuntimeException ex) {

        ex.printStackTrace();
        return new Result(Result.SERVER_ERROR, "系统异常",ex.getMessage());
    }
}
